const types = require('@babel/types')
const traverse = require('@babel/traverse').default
const generate = require('@babel/generator').default

const PropsVistor = require('../vistors/propsVistor.js')
const DataVistor = require('../vistors/dataVistor.js')
// const EventsVistor = require('./javascript/EventsVistor')
// const ComputedVistor = require('./javascript/ComputedVistor')
// const ComponentsVistor = require('./javascript/ComponentsVistor')
const LifeCycleVistor = require('../vistors/LifeCycleVistor')
// const WatchVistor = require('./javascript/WatchVistor')
const MethodsVistor = require('../vistors/methodsVistor')
// const ApplyDataVistor = require('./javascript/ApplyDataVistor')
const vistors = {
    props: new PropsVistor(),
    data: new DataVistor(),
    // events: new EventsVistor(),
    // computed: new ComputedVistor(),
    // components: new ComponentsVistor(),
    // watch: new WatchVistor(),
    lifeCycle: new LifeCycleVistor(),
    methods:new MethodsVistor(),
    // applyData:new ApplyDataVistor(),
}

const jsVistor = {
    enter(path) {
        console.log('vistor enter', path.node.type);
        // if(t.isAssignmentExpression(path)){
        //     if(vistors.applyData.is(path)){
        //         path = vistors.applyData.handle(path)
        //     }
        // }
        // if (path.node.type === 'CallExpression' && path.node.callee.name == 'Page') {
            // console.log('fmn test in path');
            if (path.node.key) {
                switch (path.node.key.name){
                    case 'data':
                        console.log('fmn test data path.node ', path.node.value);
                        path.node.value.properties.forEach(item => {
                            vistors.data.handle(item)
                        });
                        break;
                    default:
                        console.info(path.node.key.name)
                        break;
                }
            }

            if (path.node.key && path.node.value.type === 'FunctionExpression') {
                if (path.node.key.name === 'onLoad') {
                    vistors.lifeCycle.handle(path.node);
                }else{
                    vistors.methods.handle(path.node);
                }

            }
        // }
        // if(t.isClassMethod(path)){
        //     if(vistors.lifeCycle.is(path)){
        //         vistors.lifeCycle.handle(path.node)
        //     }else {
        //         vistors.methods.handle(path.node)
        //     }
        // }
    },
    exit(path){
        //do sth
        // console.log('vistor exit', path.node.type);
    }
}
const jsConverter = function(ast){
    return {
        convertedJs: traverse(ast,jsVistor),
        vistors:vistors
    }
}
module.exports = jsConverter